import { defineStore } from 'pinia'
import { AppListModel, AppListItemModel, AppIdsModel } from '/@/api/sys/model/userModel'
import { appListApi, haveAppIdsApi } from '/@/api/sys/dashboard'

interface DashboardStore {
  appList: AppListItemModel[]
  authAppList: string[]
}

export const useDashboardStore = defineStore({
  id: 'app-dashboard',
  state: (): DashboardStore => ({
    appList: [],
    authAppList: [],
  }),
  getters: {},
  actions: {
    /**
     * @description: get app list
     */
    async appList(): Promise<AppListModel> {
      try {
        const data = await appListApi()
        return data || { appList: [] }
      } catch (error) {
        return Promise.reject(error)
      }
    },
    async haveAppIds(): Promise<AppIdsModel> {
      try {
        const data = await haveAppIdsApi()
        return data || []
      } catch (error) {
        return Promise.reject(error)
      }
    },
  },
})
